package cn.neusoft.utils;

import java.io.*;

/**
 * 流的读取
 */
public class IOUtils {
    public static String readStr(InputStream inputStream){
        //声明StringBuilder 每次获取的json数据逐个追加到其中=>把读到的字符串串联起来
        StringBuilder sb = new StringBuilder();
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"));//为了读取方便 再转为字符缓冲流
            //开始读取
            String s = null;
            while ((s = bufferedReader.readLine())!=null){
                sb.append(s); //将获取的json数据追加到s中 用于将JSON字符串转为对象
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return sb.toString(); //获取完成的json字符串
    }
}
